<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script crossorigin="anonymous" integrity="sha384-6ePHh72Rl3hKio4HiJ841psfsRJveeS+aLoaEf3BWfS+gTF0XdAqku2ka8VddikM"
        src="https://lib.baomitu.com/jquery/1.11.3/jquery.min.js"></script>
    <title>算法举例-正三角形、倒三角形、等腰三角形</title>
</head>

<body>
    <script>
        $(function () {
            let number = 9
            // zheng();
            // dao();
            // dengyao();
            // 正直接三角形
            function zheng() {
                for (let i = 0; i < number; i++) {
                    console.log(out(i))
                }
            }
            //倒直接三角形
            function dao() {
                for (let i = number; i >= 0; i--) {
                    console.log(out(i))
                }
            }
            // 等腰三角形
            function dengyao() {
                let j = 0
                for (let i = number; i >= 0; i -= 2) {
                    console.log(outLine(i, j++))
                }
            }
            function outLine(n, j) {
                let str = ''
                if (j == 0) {
                    str = out(Math.floor(n / 2), " ") + out(j)
                } else {
                    str = out(Math.floor(n / 2), " ") + out(j) + out(j - 1)
                }
                return str;
            }
            function out(n, str) {
                str1 = str || '*';
                str2 = str || '*';
                for (let i = 0; i < n; i++) {
                    str2 += str1
                }
                return str2;
            }
        });
    </script>
</body>

</html>